#!/bin/sh
# Self-installing wrapper script for Digestif

set -eu

# Change this or set the DIGESTIF_HOME environment variable if you
# want to install at a different location
DIGESTIF_HOME="${DIGESTIF_HOME:-"$HOME/.digestif"}"

# Change the lines below to choose a different Lua interpreter
LUA=texlua
export LUA_PATH="$DIGESTIF_HOME/?.lua"

if [ ! -r "$DIGESTIF_HOME/bin/digestif" ]; then
    DIGESTIF_REPO="https://github.com/astoff/digestif"
    echo >&2 "Digestif not found in $DIGESTIF_HOME, fetching it now"
    mkdir -p "$DIGESTIF_HOME"
    git clone --depth 1 "$DIGESTIF_REPO" "$DIGESTIF_HOME"
    echo >&2 "Done! If you are running this interactively, press Control-C to quit."
fi

"$LUA" "$DIGESTIF_HOME/bin/digestif" "$@"
